<?php
class AppControllerAction extends Zend_Controller_Action 
{
    function init()
    {
		try {
            if(!Zend_Session::isStarted())
                Zend_Session::start();
            $testSession = new Zend_Session_Namespace('testSession');
                        
        } catch (Zend_Session_Exception $e) {
            echo "Cannot instantiate this namespace since was created";
        } 
        
        // get request language
        $lang = $this->_request->getParam('lang',null); 
        if($lang==null){  // language is null
            // get lang  from session                               
            if(!isset($testSession->current_lang)){  // not set language in session
                $lang = Zend_Registry::get("configLanguage")->test->default;
                
                if($testSession->isLocked())//unlock sessiong language
                    $testSession->unlock();
                $testSession->current_lang = $lang; 
            }   // end if  not set language in session
            else{
                $lang =  $testSession->current_lang;                  
            }
        }// end if  language is null     
        else{
            if($testSession->isLocked())//unlock sessiong language
                $testSession->unlock();
            // set language to session                              
            $testSession->current_lang = $lang;
        }     
                                                      
		$testSession->setExpirationSeconds(1*60*60*12);
        $testSession->lock();
        $this->lang=$lang;
        $this->view->lang=$lang;
            
        // separator of language is :
        $options = array('separator' => ':');
        try{
            // get language file           
            $languageDir = Zend_Registry::get("configLanguage")->test->language_dir;
            $this->view->translate = new Zend_Translate('csv', $languageDir."lang.$lang", "$lang",$options);
        }                                  
        catch (Exception $e){
            // File not found, no adapter class...
            // General failure
            throw new Exception($e->getMessage());
        } 
               
        $this->baseUrl = Zend_Registry::get("baseUrl"); 
                                                
        $frontController = Zend_Controller_Front::getInstance();  
        $request = $frontController->getRequest();
        $params = $request->getParams(); 
        $this->view->actionname = $params["action"];
        $this->view->controllername = $params["controller"];     
		
        $userModel = new Users();
        if($userModel->isAuthenticated())
        {
            $this->view->loged = true;            
        }
        else 
        {
            $this->view->loged = false;        
        }

    }
}

?>